#include <stdio.h>

void program1() {
    printf("program1 start-----------\n");
    int year, month, day;
    scanf("%d/%d/%d",&month, &day, &year);
    printf("You entered the date %d%.2d%.2d\n", year, month, day);
    printf("program1 end-----------\n");
}

void program2() {
    printf("program2 start-----------\n");
    int item_number = 0;
    float price = 0;
    int year = 0, month = 0, day = 0;

    printf("Enter item number: ");
    scanf("%d", &item_number);
    printf("Enter unit price: ");
    scanf("%f", &price);
    printf("Enter purchase date (mm/dd/yyyy): ");
    scanf("%d/%d/%d",&month, &day, &year);

    printf("Item\tUnit\tPurchase\n");
    printf("\tPrice\tDate\n");
    printf("%d\t$%d\t%.2d/%.2d/%d\n", &item_number, &price, &month, &day, &year);
    printf("program2 end-----------\n");
}

void program3() {
    printf("program3 start-----------\n");
    int prefix = 0, group_identifier = 0, public_code = 0, item_number, check_digit;
    printf("Enter ISBN: ");
    scanf("%d-%d-%d-%d-%d", &prefix, &group_identifier,
          &public_code, &item_number, &check_digit);
    printf("GS1 prefix: %d\n", prefix);
    printf("Group identifier: %d\n", group_identifier);
    printf("Publisher code: %d\n", public_code);
    printf("Item number: %d\n", item_number);
    printf("Check digit: %d\n", check_digit);

    printf("program3 end-----------\n");
}

void program4() {
    printf("program4 start-----------\n");
    int prefix = 0, number1 = 0, number2 = 0;
    printf("Enter phone number [(xxx) xxx-xxxx]: ");
    scanf("(%d) %d-%d", &prefix, &number1,
          &number2);
    printf("You entered : %d.%d.%d\n", prefix, number1, number2);

    printf("program4 end-----------\n");
}

void program5() {
    printf("program5 start-----------\n");
    int a1, a2, a3, a4;
    int b1, b2, b3, b4;
    int c1, c2, c3, c4;
    int d1, d2, d3, d4;
    printf("Enter the numbers from 1 to 16 in any order: ");
    scanf("%d %d %d %d", &a1, &a2, &a3, &a4);
    scanf("%d %d %d %d", &b1, &b2, &b3, &b4);
    scanf("%d %d %d %d", &c1, &c2, &c3, &c4);
    scanf("%d %d %d %d", &d1, &d2, &d3, &d4);
    int row_sums1 = a1 + a2 + a3 + a4;
    int row_sums2 = b1 + b2 + b3 + b4;
    int row_sums3 = c1 + c2 + c3 + c4;
    int row_sums4 = d1 + d2 + d3 + d4;

    int cloumn_sums1 = a1 + b1 + c1 + d1;
    int cloumn_sums2 = a2 + b2 + c2 + d2;
    int cloumn_sums3 = a3 + b3 + c3 + d3;
    int cloumn_sums4 = a4 + b4 + c4 + d4;

    int diagonal_sums1 = a1 + b2 + c3 + d4;
    int diagonal_sums2 = a4 + b3 + c2 + d1;
    printf("Row sums: %d %d %d %d\n", row_sums1, row_sums2, row_sums3, row_sums4);
    printf("Column sums: %d %d %d %d\n", cloumn_sums1, cloumn_sums2, cloumn_sums3, cloumn_sums4);
    printf("Diagonal sums: %d %d\n", diagonal_sums1, diagonal_sums2);

    printf("program5 end-----------\n");
}

void program6() {
    printf("program6 start-----------\n");
    int num1, denom1, num2, denom2, result_num, result_denom;
    printf("Enter two fraction separated by a plus sign: ");
    scanf("%d/%d+%d/%d", &num1, &denom1, &num2, &denom2);

    result_num = num1 * denom2 + num2 * denom1;
    result_denom = denom1 * denom2;
    printf("The sum is %d/%d\n", result_num, result_denom);

    printf("program6 end-----------\n");
}

int main(void) {
/**
 d ——表示十进制（基数为 10）形式的整数。p 指明了待显示数字的最少个数（必
要时在数前加上额外的零）；如果省略 p，则默认它的值为 1。
 e ——表示指数（科学记数法）形式的浮点数。p 指明了小数点后应该出现的数字个数
（默认值为 6）。如果 p 为 0，则不显示小数点。
 f ——表示“定点十进制”形式的浮点数，没有指数。p 的含义与说明符 e 中的一样。
 g ——表示指数形式或者定点十进制形式的浮点数，形式的选择根据数的大小决定。p
意味着可以显示的有效数字（不是小数点后的数字）的最大数量。与转换指定符 f 不同，
g 的转换将不显示尾随的零。此外，如果要显示的数值没有小数点后的数字，g 就不会
显示小数点。
 */
    program6();
    float x = 382.24f;
    printf("3.1 -  4\n");
    int i;
    float x4, j;
    // 输入->12.3 45.6 789,我估计只有x4有值，其他都没有值
    // 我本地输出：x4=12.3, i=45, j=0.6000003.1 -  3
    // 官方答案 The values of x, i, and y will be 12.3, 45, and .6, respectively.
    scanf("%f%d%f", &x4, &i, &j);
    printf("x4=%.1f, i=%d, j=%f", x4, i, j);
    printf("3.1 -  3\n");
    /*
 (a) "%d"与" %d"。 后者需要多输入一个空格在输入数字
 (b) "%d-%d-%d"与"%d -%d -%d"。 后者是空格加-再输入数字
 (c) "%f"与"%f "。输入玩数字后需要加空格
 (d) "%f,%f"与"%f, %f"。输入完,后需要输入空格

     */
    printf("3.1 -  2\n");
    printf("%-8.1e\n", x);
    printf("%10.6e\n", x);
    printf("%-8.3f\n", x);
    printf("%6.0f\n", x);
    printf("3.1 -  1\n");
    printf("%6d, %4d\n", 86, 1040);
    printf("%12.5e\n", 30.253);
    printf("%.4f\n", 83.162);
    printf("%-6.2g\n", 0.0000009979);
}